﻿<%@ Page Title="" Language="C#" MasterPageFile="~/PageMaster/Site1.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="EMS20.UI.Admin.Cate.Index" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        #zhegai {
            position: absolute;
            top: 0px;
            left: 0px;
            width: 100%;
            height: 100%;
            background-color: #000;
            opacity: 0.4;
            z-index: 1;
            display: none;
        }

        #EditDiv {
            position: absolute;
            top: 270px;
            left: 450px;
            z-index: 999;
            background-color: white;
            display: none;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table class="list">
        <tr>
            <td colspan="4">
                <input type="button" onclick="Add()" value="新增" /></td>
        </tr>
        <tr>
            <th>ID</th>
            <th>类别</th>
            <th>标题</th>
            <th>操作</th>
        </tr>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <tr>
                    <td><%#Eval("c_id") %></td>
                    <td><%#Eval("c_type") %></td>
                    <td><%#Eval("c_title") %></td>
                    <td><a href="javascript:void(0)" onclick="Delete(<%#Eval("c_id") %>)">删除</a> | <a href="javascript:void(0)" onclick="Edit(<%#Eval("c_id") %>)">修改</a></td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
    </table>
    <div id="zheGai">
    </div>
    <div id="EditDiv">
        <form id="f1">
            <input type="hidden" id="id" name="id" />
            <table class="list">
                <tr>
                    <th>类别id</th>
                    <td>
                        <input type="text" id="name" name="name" /></td>
                </tr>
                <tr>
                    <th>标题</th>
                    <td>
                        <input type="text" id="title" name="title" /></td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        <input type="button" onclick="Sure()" id="btn" />
                        |
                        <input type="button" value="取消" onclick="closeEdit()" /></td>
                </tr>
            </table>
        </form>
    </div>
    <script src="/js/Help.js"></script>
    <script type="text/javascript">
        var isEdit

        //删除操作
        function Delete(id) {
            $.getJSON("/Admin/Cate/ProcessAjax.ashx?type=Del", "id=" + id, function (data) {
                help.switchacase(data, function () {
                    msgBox.showMsgOk(data.Msg, function () {
                        window.location = window.location;
                    });
                });
            });
        }


        //打开修改面板
        function openEdit() {
            $('#zheGai,#EditDiv').show();
        }

        //关闭修改面板
        function closeEdit() {
            $('#zheGai,#EditDiv').hide();
        }

        function Edit(id) {
            $.getJSON("/Admin/Cate/ProcessAjax.ashx?type=GetEntity", "id=" + id, function (data) {

                help.switchacase(data, function () {
                    var model = data.Data;
                    $('#name').val(model['c_type']);
                    $('#title').val(model['c_title']);
                    $('#id').val(id);
                    $('#btn').val('修改');
                    isEdit = true;
                    openEdit();
                });
            });
        }

        //提交操作
        function Sure() {
            if (isEdit) {
                var params = $('#f1').serialize();

                $.post('/Admin/Cate/ProcessAjax.ashx?type=Edit', params, function (data) {
                    help.switchacase(data, function () {
                        window.location = window.location;
                    });
                }, 'json');
            }
            else {
                var params = $('#f1').serialize();

                $.post('/Admin/Cate/ProcessAjax.ashx?type=Add', params, function (data) {
                    help.switchacase(data, function () {
                        msgBox.showMsgOk(data.Msg, function () {
                            window.location = window.location;
                        });
                    });
                }, 'json');
            }
        }

        function Add() {
            $("#name").val("");
            $("#title").val("");
            $("#id").val("");
            $("#btn").val("新增");
            isEdit = false;
            openEdit();
        }
    </script>
</asp:Content>
